<?php
namespace app\admin\controller;

use think\Controller;
use app\admin\classes\AdminUser as User;
use core\Api;
use core\Func;

class Login extends Controller {



  public function index($to=""){


    $data=[
      "title"=>config("site.title"),
      "to"=>$to,
    ];

    return view("/login/index",$data);

  }

  public function login(User $user,$username='',$password=''){
    empty($username) and Api::error('请输入用户名');
    empty($password) and Api::error('密码不能为空');

    if($user->login($username,$password)){
      Api::ok("登录成功");
    }else{
      Api::error('用户名或密码错误');
    }
  }

  public function logout(User $user){
    // session("user",null);
    $user->logout();

    $url=Func::getHash()."/index";
    $this->redirect($url);
  }

}
